package com.kukudexin.time.mayikt.stream;

import com.kukudexin.time.mayikt.entity.UserEntity;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author: 酷酷的鑫
 * @Date: 2022/1/12 11:06
 * @description:
 */
public class ToMapLambdaTest {
    public static void main(String[] args) {
        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity("mayikt", 20));
        userEntities.add(new UserEntity("meite", 28));
        userEntities.add(new UserEntity("zhangsan", 35));


        Map<String, UserEntity> collect = userEntities.stream().collect(Collectors.toMap(new Function<UserEntity, String>() {
            @Override
            public String apply(UserEntity userEntity) {
                return null;
            }
        }, new Function<UserEntity, UserEntity>() {
            @Override
            public UserEntity apply(UserEntity userEntity) {
                return userEntity;
            }
        }, new BinaryOperator<UserEntity>() {
            @Override
            public UserEntity apply(UserEntity userEntity, UserEntity userEntity2) {
                return userEntity;
            }
        }));

        Map<String, UserEntity> collect2 = userEntities.stream().collect(Collectors.toMap(k -> k.getUserName(), userEntity -> userEntity, (userEntity, userEntity2) -> userEntity));
        Map<String, UserEntity> collect3 = userEntities.stream().collect(Collectors.toMap(k -> k.getUserName(), Function.identity(), (userEntity, userEntity2) -> userEntity));
        Map<String, UserEntity> collect4 = userEntities.stream().collect(Collectors.toMap(UserEntity::getUserName, userEntity -> userEntity, (userEntity, userEntity2) -> userEntity));




    }

}
